﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NLog;
using System.Drawing;
using System.Collections;
using System.Collections.ObjectModel;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
using System.Data;
using System.IO;
using System.Diagnostics;



namespace PhotoADSync
{
    class ExportLogo
    {
        private static Logger myLogger = LogManager.GetCurrentClassLogger();

        public Datenbank DB { get; set; }

        public ExportLogo(Datenbank db)
        {
            DB = db;
        }

        /// <summary>
        ///  Holt OID, Mailadresse, Pisa-User-Photo aus der Datenbank
        /// </summary>
        /// <returns> Arraylist befüllt mit Logo-Objekten</returns>
        public ArrayList DbtoLogoList()
        {
            string sql = Properties.Settings.Default.Logo;
            Logo l = new Logo();
            ArrayList logos = new ArrayList();
            
            try 
            {
                OracleCommand cmd = new OracleCommand(sql, DB.OraVerbindung);
                
                    cmd.InitialLONGFetchSize = -1;
                    OracleDataReader reader = cmd.ExecuteReader();

                        while (reader.Read())
                        {
                            String sOID = reader.GetString(0);
                            String sMailadresse = reader.GetString(1);
                            OracleBinary longraw = reader.GetOracleBinary(2);

                            l = new Logo(sOID, sMailadresse, longraw);
                            logos.Add(l);
                            myLogger.Info("Userobjekt: " + sMailadresse + " erfolgreich erstellt.");
                        }
                       
                        reader.Close();
                        reader.Dispose();
            }
            catch(Exception ex)
            {
                myLogger.FatalException("Hinzufügen des Logos nicht möglich.", ex);
            }

            return logos;
            
        }
        
        

    }
}
